from http_method import HttpMethod, HttpAccount

http_method = HttpMethod("192.168.100.25", 80, "loadmin", "admin_123")
http_account = HttpAccount("192.168.100.25", 80)

#携带token访问接口
def interface_test(url, param):
    res = http_method.UAPI_POST(url, param)
    ret = http_method.getStatusCode(res)
    resData = http_method.getResData(res)
    return ret, resData

#不携带token访问接口
def interface_test_notoken(url, param):
    res = http_account.ACC_UAPI_POST(url, param)
    ret = http_account.getStatusCode(res)
    resData = http_account.getResData(res)
    return ret, resData

if __name__ == '__main__':
    url = "/openAPI/privateCon/v1/forward/config/add"
    num = 100
    for i in range(1, num + 1):
        param = {
            "ForwardRuleName": "RuleName_" + str(i),
            "ForwardType": 0,
            "ForwardMode": 0,
            "ForwardAddress": "192.168.100.25",
            "ForwardPort": i,
            "StartTime": "2024-06-18 19:10:13",
            "EndTime": "2999-12-31 23:59:59",
            "ForwardResourceList": [
                {
                    "ResCode": "org@30688#20240611203749",
                    "ResType": 2,
                    "ResName": "sppp"
                }
            ]
        }
        ret, resData = interface_test(url, param)
        if ret == 0:
            print(f"第{i}次接口调用成功，返回错误码为: {ret}, 返回数据为{resData}")
        else:
            print(f"第{i}次接口调用失败，返回错误码为: {ret}, 返回数据为{resData}")


